<script type="text/javascript" language="javascript">
    //    $(document).ready(function(){
    //        var acount = $('#acount').val();
    //        $('#formdangky').submit(function(){
    //            var acount = $('#acount').val();
    //            $('.message').hide();
    //            if(acount == ''){
    //                $('.message').html('khong duoc de trong').css('color', 'red').show();
    //                $('#acount').focus();
    //                return false;
    //            }
    //        });
    //        
    //        $('#acount').keyup(function(){
    //            var acount = $('#acount').val();
    //            $('.message').hide();
    //            if(acount.length <4){
    //                $('.message').html('ten dang nhap phai dai hon 4 ky tu').css('color','red').show();
    //                return false;
    //            }
    //            var regx = /^[a-zA-Z]+$/;
    //            if(!regx.test(acount)){
    //                $('.message').html('ten dang nhap chi chap nhan ky tu khong co so').css('color','red').show();
    //                return false;
    //            }
    //        });
    //    });

    function proccessForm(string){
        setTimeout(function(){
            var getData1 = $.parseJSON(string);
            if(getData1.errors == true){
                $("#formdangky").hide();
                $("#formSuccess").show();
            }else{
                if(getData1.er_user || getData1.er_user == ""){
                    $("#er_acount").html(getData1.er_user);
                }
                if(getData1.er_pass || getData1.er_pass == ""){
                    $("#er_password").html(getData1.er_pass);
                }
                if(getData1.er_repass || getData1.er_repass == ""){
                    $("#er_repassword").html(getData1.er_repass);
                }
                if(getData1.er_fullname || getData1.er_fullname == ""){
                    $("#er_fullName").html(getData1.er_fullname);
                }
                if(getData1.er_addr || getData1.er_addr == ""){
                    $("#er_address").html(getData1.er_addr);
                }
                if(getData1.er_email || getData1.er_email == ""){
                    $("#er_email").html(getData1.er_email);
                }
                if(getData1.er_quest || getData1.er_quest == ""){
                    $("#er_quest").html(getData1.er_quest);
                }
                if(getData1.er_answers || getData1.er_answers == ""){
                    $("#er_answers").html(getData1.er_answers);
                }
                if(getData1.er_captcha || getData1.er_captcha == ""){
                    $("#er_captcha").html(getData1.er_captcha);
                }
            }
        },1000);
        
    }

    $(document).ready(function(){
        $(".error").hide();
        $('#formdangky').submit(function(eve){
            eve.preventDefault();
            $.ajax({
                url: '<?= base_url(); ?>dang_ky/xl_dangky',
                type: 'POST',
                dataType: 'html',
                data: $('#formdangky').serialize(),
                beforeSend: function(){
                    $(".error").prepend("<img src='<?= base_url(); ?>images/ajax-loader.gif' width='20' height='20'/>").show();
                },
                success: function(string){
                    proccessForm(string);
                },
                error: function(){
                    alert('Co loi xay ra');
                } 
            })
        });
    });
       
</script>
<div class="bdcrumb"><? echo $this->breadcrumb->output(); ?></div>
<div class="ds-sanpham">
    <form id="formdangky" name="formdangky" method="post" action="<?= base_url(); ?>dang_ky/xl_dangky">
        <fieldset id="main">
            <legend>Đăng ký</legend>
            <div id="InforAcc">
                <h2>Thông tin tài khoản</h2>
                <fieldset>
                    <label for="acount">Tên đăng nhập: </label>
                    <input type="text" name="acount" id="acount"/><span id="er_acount" class="error"></span>
                </fieldset>
                <fieldset>
                    <label for="password">Mật khẩu: </label>
                    <input type="password" name="password" id="password"/><span id="er_password" class="error"></span>
                </fieldset>
                <fieldset>
                    <label for="Repassword">Nhập lại mật khẩu: </label>
                    <input type="password" name="repassword" id="repassword"/><span id="er_repassword" class="error"></span>
                </fieldset>
            </div>
            <div id="InforUser">
                <h2>Thông tin người dùng</h2>
                <fieldset>
                    <label for="fullname">Họ và tên: </label>
                    <input type="text" name="fullName" id="fullName"/><span id="er_fullName" class="error"></span>
                </fieldset>
                <fieldset>
                    <label for="address">Địa chỉ: </label>
                    <input type="text" name="address" id="address"/><span id="er_address" class="error"></span>
                </fieldset>
                <fieldset>
                    <label for="email">Email: </label>
                    <input type="text" name="email" id="email"/><span id="er_email" class="error"></span>
                </fieldset>
                <fieldset>
                    <label for="phone">Số điện thoại: </label>
                    <input type="text" name="phone" id="phone"/>
                </fieldset>
                <fieldset>
                    <label for="gioitinh">Giới tính: </label>
                    <select name="gender" id="gender">
                        <option value="1">Nam</option>
                        <option value="0">Nữ</option>
                    </select>
                </fieldset>
                <fieldset>
                    <label for="quests">Câu hỏi bí mật: </label>
                    <select name="quest" id="quest"><span id="er_quest" class="error"></span>
                        <option value="">-- Chọn một câu hỏi --</option>
                        <? foreach ($quest as $row): ?>
                            <option value="<?= $row->QID ?>"><?= $row->QContent ?></option>
                        <? endforeach; ?>
                    </select>
                </fieldset>
                <fieldset>
                    <label for="aswers">Câu trả lời: </label>
                    <input type="text" name="answers" id="answers" name="answers"/><span id="er_answers" class="error"></span>
                </fieldset>
            </div>
            <div id="BaoMat">
                <h2>Mã bảo mật</h2>
                <fieldset>
                    <label for="capt">Mã kiểm tra: </label>
                    <span><?= $cap; ?></span>
                <fieldset>
                    <label for="captcha">Nhập mã kiểm cha: </label>
                    <input type="text" name="captcha_input" id="answers" name="answers"/><span id="er_captcha" class="error"></span>
                </fieldset>
                <fieldset id="btn">
                    <input type="submit" id="btnsubmit" value="gửi"/>
                    <input type="reset" id="btnreset" value="xóa"/>
                </fieldset>
            </div>
        </fieldset>
    </form>
    <div id="formSuccess" style="display: none;">
        <p>Cảm ơn bạn đã đăng ký, vui lòng <a href="<?= base_url(); ?>user/view_login">vào đây đăng nhập</a> để sử dụng các dịch vụ của website</p>
    </div>
</div>